1 About scTensor Algorithm

scTensor is the R/Bioconductor package for visualization of cell-cell interaction within single-cell RNA-Seq data. The calculation consists of several steps.

Firstly, LRBase.XXX.eg.db-type package is loaded for retriving ligand-receptor gene relationship (XXX is the abbreviation of some organisms like “Hsa” as Homo sapiens). scTensor searches the corresponding pair of genes in the rownames of input data matrix and extracted as vector. In this step, the gene identifier is limited as NCBI Gene ID for now.

Next, the all elements of extracted two vectors are summed up with all possible combination (Kronecker sum) and summarized as a matrix. Here, the multiple matrices can be represented as a three-order “tensor” (Ligand-Cell * Receptor-Cell * LR-Pair). scTensor decomposes the tensor into a small tensor (core tensor) and three factor matrices. Tensor decomposition is very similar to the matrix decomposition like PCA (principal component analysis). The core tensor is similar to eigenvalue of PCA and means how much the pattern is outstanding. Likewise, three matrices is similar to the PC scores and loadings of PCA and represents which ligand-cell/receptor-cell/LR-pair are informative. When the matrices have negative values, distinguishing that which direction (+/-) is important and which is not, is difficult to interpret and laboring task. That’s why, scTensor performs non-negative Tucker decomposition (NTD), which is non-negative version of Tucker decomposition (c.f. nnTensor).

Finaly, the result of NTD is summarized as this report. Most of plots belows are visualized by plotly package and interactively search the presise information of the plot. The three factor matrices can be interactively viewed and which celltypes are responds to the cell-cell interaction.The mode-3 (LR-pair) direction of sum of the core tensor is calculated and visualized as Ligand-Receptor Patterns. Detail of (Ligand-Cell, Receptor-Cell, LR-pair) Patterns are also visualized as below.

For more detail, visit the vignette of scTensor

2 Global statistics and plots

The result of scTensor is saved as a R binary file (reanalysis.RData).

load("reanalysis.RData")

# SingleCellExperiment object
sce
## class: SingleCellExperiment 
## dim: 242 852 
## metadata(10): lrbase color ... relchange hexbin
## assays(2): counts normcounts
## rownames(242): 72 9510 ... 58189 7538
## rowData names(0):
## colnames(852): M_4W_embryo1_sc52 M_4W_embryo1_sc53 ...
##   M_25W_embryo1_107_sc51 M_25W_embryo1_107_sc52
## colData names(0):
## reducedDimNames(1): TSNE
## spikeNames(0):
## altExpNames(0):
# Data size
metadata(sce)$datasize
## [1] 7 7 4
# Reduced data size
metadata(sce)$ranks
## [1] 4 4
# Reconstruction Error of NTD
head(metadata(sce)$recerror)
##      offset           1           2           3           4           5 
## 0.000000001 1.324695819 1.286015847 1.271298111 1.254054029 1.231860433
tail(metadata(sce)$recerror)
##       25       26       27       28       29       30 
## 1.158253 1.157022 1.156018 1.155187 1.154478 1.153856
# Relative Change of NTD
head(metadata(sce)$relchange)
##      offset           1           2           3           4           5 
## 0.000000001 0.641594419 0.030077368 0.011576935 0.013750669 0.018016323
tail(metadata(sce)$relchange)
##           25           26           27           28           29           30 
## 0.0012850998 0.0010639917 0.0008685112 0.0007196564 0.0006138594 0.0005386907
# Gene expression matrix
is(input)
## [1] "matrix"           "array"            "mMatrix"          "AnyMatrix"       
## [5] "structure"        "vector"           "vector_OR_factor" "vector_OR_Vector"
dim(input)
## [1] 242 852
input[seq_len(2), seq_len(2)]
##      M_4W_embryo1_sc52 M_4W_embryo1_sc53
## 72            3.372542          3.180208
## 9510          1.033941          0.000000
# The result of 2D dimensional reduction (e.g. t-SNE)
is(twoD)
## [1] "matrix"           "array"            "mMatrix"          "AnyMatrix"       
## [5] "structure"        "vector"           "vector_OR_factor" "vector_OR_Vector"
dim(twoD)
## [1] 852   2
head(twoD)
##                       [,1]      [,2]
## M_4W_embryo1_sc52 16.27250 1.8273633
## M_4W_embryo1_sc53 17.41540 1.1278984
## M_4W_embryo1_sc54 16.20873 0.4803177
## M_4W_embryo1_sc55 14.91489 1.8113621
## M_4W_embryo1_sc56 14.90168 2.6814108
## M_4W_embryo1_sc57 16.41085 1.1939982
# Ligand-Receptor corresponding table extracted from LRBase.XXX.eg.db
is(LR)
##  [1] "data.frame"       "list"             "oldClass"         "data.frameOrNULL"
##  [5] "DfOrNULL"         "vector"           "listOrNULL"       "list_OR_List"    
##  [9] "AssayData"        "ListOrEnv"        "vector_OR_factor" "vector_OR_Vector"
dim(LR)
## [1] 34565     3
head(LR, 2)
##   GENEID_L GENEID_R
## 1     4016       14
## 2   344752       14
##                                                                                                                      SOURCEID
## 1 7689553|14702039|16572171|15489334|17690259|18037624|18669648|19343041|7743515|15489334|10329261|18634987|21269460|24275569
## 2                                             17974005|16641997|15489334|7743515|15489334|10329261|18634987|21269460|24275569
# Celltype label and color scheme
is(celltypes)
##  [1] "character"               "vector"                 
##  [3] "data.frameRowLabels"     "SuperClassMethod"       
##  [5] "characterORconnection"   "character_OR_NULL"      
##  [7] "atomic"                  "EnumerationValue"       
##  [9] "characterORMIAME"        "index"                  
## [11] "atomicVector"            "characterOrRle"         
## [13] "FactorOrCharacterOrNULL" "OptionalCharacter"      
## [15] "vector_OR_factor"        "vector_OR_Vector"
length(celltypes)
## [1] 852
head(celltypes)
## Male_FGC_1 Male_FGC_1 Male_FGC_1 Male_FGC_1 Male_FGC_1 Male_FGC_1 
##  "#9E0142"  "#9E0142"  "#9E0142"  "#9E0142"  "#9E0142"  "#9E0142"
# Core tensor values
is(index)
## [1] "matrix"           "array"            "mMatrix"          "AnyMatrix"       
## [5] "structure"        "vector"           "vector_OR_factor" "vector_OR_Vector"
dim(index)
## [1] 16  4
head(index)
##      Mode1 Mode2    Value Rank
## [1,]     2     3 6.570272    1
## [2,]     2     2 6.116620    2
## [3,]     1     3 4.836773    3
## [4,]     1     2 4.738209    4
## [5,]     4     3 4.073323    5
## [6,]     3     3 3.531418    6
is(corevalue)
##  [1] "numeric"          "vector"           "atomic"           "EnumerationValue"
##  [5] "index"            "replValue"        "numLike"          "number"          
##  [9] "atomicVector"     "numericVector"    "NumericOrNULL"    "vector_OR_factor"
## [13] "vector_OR_Vector" "replValueSp"      "Mnumeric"
length(corevalue)
## [1] 16
head(corevalue)
##     selected     selected not selected not selected not selected not selected 
##    13.474056    12.543724     9.919065     9.716934     8.353411     7.242094
# Selected corevalue position with thr threshold "thr"
is(selected)
##  [1] "integer"             "double"              "numeric"            
##  [4] "vector"              "data.frameRowLabels" "atomic"             
##  [7] "integer_OR_LLint"    "EnumerationValue"    "atomicVector"       
## [10] "numericVector"       "integer_OR_NULL"     "integerOrRle"       
## [13] "integer or NULL"     "vector_OR_factor"    "vector_OR_Vector"   
## [16] "index"               "replValue"           "numLike"            
## [19] "number"              "Mnumeric"            "NumericOrNULL"      
## [22] "replValueSp"
length(selected)
## [1] 2
head(selected)
## [1] 1 2
# The result of 2-class clustering
# The result of analysis in each L vector
is(ClusterL)
## [1] "matrix"           "array"            "mMatrix"          "AnyMatrix"       
## [5] "structure"        "vector"           "vector_OR_factor" "vector_OR_Vector"
dim(ClusterL)
## [1] 4 7
# The result of analysis in each R vector
is(ClusterR)
## [1] "matrix"           "array"            "mMatrix"          "AnyMatrix"       
## [5] "structure"        "vector"           "vector_OR_factor" "vector_OR_Vector"
dim(ClusterR)
## [1] 4 7
# The result of analysis in each LR vector
is(out.vecLR)
## [1] "list"             "vector"           "listOrNULL"       "list_OR_List"    
## [5] "AssayData"        "ListOrEnv"        "vector_OR_factor" "vector_OR_Vector"

2.1 Number of cells in each celltype

color <- names(celltypes)
colors <- celltypes[vapply(unique(color), function(x){which(color == x)[1]}, 0L)]
numcells <- vapply(names(colors), function(x){length(which(color == x))}, 0L)
numcells <- data.frame(numcells=numcells, celltypes=names(numcells))

suppressPackageStartupMessages(library(plotly))
plot_ly(numcells, x=~celltypes, y=~numcells, type="bar", marker = list(color = colors))

2.2 Number of expressed genes in each celltype (Non-zero genes)

expgenes <- apply(input, 2, function(x){length(which(x != 0))})
expgenes <- data.frame(expgenes=expgenes, celltypes=names(celltypes))
plot_ly(expgenes, y=~expgenes, color=color, colors=colors, type="box")

2.3 Two dimensional plot of all cells

plot_ly(x=twoD[,1], y=twoD[,2], color = color, colors = colors, type = "scatter", text = rownames(twoD), mode = "markers")

2.4 Distribution of core tensor values

corenames <- vapply(seq_len(nrow(index)), function(x){paste(index[x,seq_len(3)], collapse=",")}, "")
plot_ly(x=seq_along(corevalue), y=corevalue, type="bar", color=names(corevalue), text=corenames, colors = c("#999999", "#E41A1C"))

3 Ligand-Cell Patterns

suppressPackageStartupMessages(library("heatmaply"))
l <- metadata(sce)$sctensor$ligand
if(nrow(l) >= 2){
rownames(l) <- paste0("(",seq_len(nrow(l)), ",*,*)")
heatmaply(l,xlab="Celltype",ylab="Pattern",fontsize_col=20,fontsize_row=20,subplot_widths=c(0.7, 0.1),subplot_heights=c(0.2, 0.7),labRow = rownames(l),labCol = colnames(l))
}

3.1 (1,,)-Pattern = Male_Soma_1

3.2 (2,,)-Pattern = Male_Soma_4 & Male_Soma_3

3.3 (3,,)-Pattern = Male_Soma_2

3.4 (4,,)-Pattern = Male_FGC_3 & Male_Soma_3

4 Receptor-Cell Patterns

r <- metadata(sce)$sctensor$receptor
if(nrow(r) >= 2){
rownames(r) <- paste0("(*,",seq_len(nrow(r)), ",*)")
heatmaply(r,xlab="Celltype",ylab="Pattern",fontsize_col=20,fontsize_row=20,subplot_widths=c(0.7, 0.1),subplot_heights=c(0.2, 0.7),labRow = rownames(r),labCol = colnames(r))
}

4.1 (,1,)-Pattern = Male_Soma_2

4.2 (,2,)-Pattern = Male_Soma_3

4.3 (,3,)-Pattern = Male_Soma_1

4.4 (,4,)-Pattern = Male_Soma_4

5 CCI-wise Hypergraph

6 Gene-wise Hypergraph

library("scTensor")
load("reanalysis.RData")

scTensor:::.myvisNetwork(g)

Details of Ligand Gene-centric Overview (selected)

Details of Ligand Gene-centric Overview (all)

Details of Receptor Gene-centric Overview (selected)

Details of Receptor Gene-centric Overview (all)

8 Session Information

sessionInfo()
## R version 3.6.3 (2020-02-29)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 18.04.4 LTS
## 
## Matrix products: default
## BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
## 
## locale:
##  [1] LC_CTYPE=ja_JP.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=ja_JP.UTF-8        LC_COLLATE=ja_JP.UTF-8    
##  [5] LC_MONETARY=ja_JP.UTF-8    LC_MESSAGES=ja_JP.UTF-8   
##  [7] LC_PAPER=ja_JP.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=ja_JP.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] parallel  stats4    stats     graphics  grDevices utils     datasets 
## [8] methods   base     
## 
## other attached packages:
##  [1] heatmaply_1.1.0             viridis_0.5.1              
##  [3] viridisLite_0.3.0           BiocStyle_2.14.4           
##  [5] plotly_4.9.2.1              ggplot2_3.3.1              
##  [7] GO.db_3.10.0                org.Hs.eg.db_3.10.0        
##  [9] AnnotationDbi_1.48.0        IRdisplay_0.7.0            
## [11] MeSH.Hsa.eg.db_1.13.0       MeSHDbi_1.22.0             
## [13] LRBase.Hsa.eg.db_1.2.0      LRBaseDbi_1.4.0            
## [15] SingleCellExperiment_1.8.0  SummarizedExperiment_1.16.1
## [17] DelayedArray_0.12.3         BiocParallel_1.20.1        
## [19] matrixStats_0.56.0          Biobase_2.46.0             
## [21] GenomicRanges_1.38.0        GenomeInfoDb_1.22.1        
## [23] IRanges_2.20.2              S4Vectors_0.24.4           
## [25] BiocGenerics_0.32.0         scTensor_1.4.0             
## 
## loaded via a namespace (and not attached):
##   [1] rsvd_1.0.3                    Hmisc_4.4-0                  
##   [3] ica_1.0-2                     Rsamtools_2.2.3              
##   [5] foreach_1.5.0                 lmtest_0.9-37                
##   [7] crayon_1.3.4                  MASS_7.3-51.6                
##   [9] nlme_3.1-148                  backports_1.1.7              
##  [11] GOSemSim_2.12.1               rlang_0.4.6                  
##  [13] XVector_0.26.0                ROCR_1.0-11                  
##  [15] irlba_2.3.3                   nnTensor_1.0.5               
##  [17] GOstats_2.52.0                tagcloud_0.6                 
##  [19] bit64_0.9-7                   glue_1.4.1                   
##  [21] sctransform_0.2.1             dotCall64_1.0-0              
##  [23] DOSE_3.12.0                   tidyselect_1.1.0             
##  [25] fitdistrplus_1.1-1            XML_3.99-0.3                 
##  [27] tidyr_1.1.0                   zoo_1.8-8                    
##  [29] GenomicAlignments_1.22.1      xtable_1.8-4                 
##  [31] magrittr_1.5                  evaluate_0.14                
##  [33] zlibbioc_1.32.0               rstudioapi_0.11              
##  [35] rpart_4.1-15                  fastmatch_1.1-0              
##  [37] ensembldb_2.10.2              maps_3.3.0                   
##  [39] fields_10.3                   shiny_1.4.0.2                
##  [41] xfun_0.14                     askpass_1.1                  
##  [43] cluster_2.1.0                 caTools_1.18.0               
##  [45] tidygraph_1.2.0               TSP_1.1-10                   
##  [47] pbdZMQ_0.3-3                  tibble_3.0.1                 
##  [49] interactiveDisplayBase_1.24.0 ggrepel_0.8.2                
##  [51] biovizBase_1.34.1             ape_5.4                      
##  [53] listenv_0.8.0                 dendextend_1.13.4            
##  [55] Biostrings_2.54.0             png_0.1-7                    
##  [57] future_1.17.0                 withr_2.2.0                  
##  [59] bitops_1.0-6                  ggforce_0.3.1                
##  [61] RBGL_1.62.1                   plyr_1.8.6                   
##  [63] GSEABase_1.48.0               AnnotationFilter_1.10.0      
##  [65] pillar_1.4.4                  gplots_3.0.3                 
##  [67] GenomicFeatures_1.38.2        graphite_1.32.0              
##  [69] europepmc_0.4                 vctrs_0.3.1                  
##  [71] ellipsis_0.3.1                generics_0.0.2               
##  [73] plot3D_1.3                    urltools_1.7.3               
##  [75] MeSH.Aca.eg.db_1.13.0         outliers_0.14                
##  [77] tools_3.6.3                   foreign_0.8-76               
##  [79] entropy_1.2.1                 munsell_0.5.0                
##  [81] tweenr_1.0.1                  fgsea_1.12.0                 
##  [83] fastmap_1.0.1                 compiler_3.6.3               
##  [85] abind_1.4-5                   httpuv_1.5.4                 
##  [87] rtracklayer_1.46.0            Gviz_1.30.3                  
##  [89] GenomeInfoDbData_1.2.2        gridExtra_2.3                
##  [91] lattice_0.20-41               visNetwork_2.0.9             
##  [93] AnnotationForge_1.28.0        later_1.1.0.1                
##  [95] dplyr_1.0.0                   BiocFileCache_1.10.2         
##  [97] jsonlite_1.6.1                scales_1.1.1                 
##  [99] graph_1.64.0                  pbapply_1.4-2                
## [101] genefilter_1.68.0             lazyeval_0.2.2               
## [103] promises_1.1.0                MeSH.db_1.13.0               
## [105] latticeExtra_0.6-29           reticulate_1.16              
## [107] checkmate_2.0.0               rmarkdown_2.2                
## [109] cowplot_1.0.0                 schex_1.0.55                 
## [111] MeSH.Syn.eg.db_1.13.0         webshot_0.5.2                
## [113] Rtsne_0.15                    dichromat_2.0-0              
## [115] BSgenome_1.54.0               uwot_0.1.8                   
## [117] igraph_1.2.5                  gclus_1.3.2                  
## [119] survival_3.1-12               yaml_2.2.1                   
## [121] plotrix_3.7-8                 htmltools_0.4.0              
## [123] memoise_1.1.0                 VariantAnnotation_1.32.0     
## [125] rTensor_1.4.1                 Seurat_3.1.5                 
## [127] seriation_1.2-8               graphlayouts_0.7.0           
## [129] digest_0.6.25                 assertthat_0.2.1             
## [131] ReactomePA_1.30.0             mime_0.9                     
## [133] rappdirs_0.3.1                repr_1.1.0                   
## [135] registry_0.5-1                spam_2.5-1                   
## [137] RSQLite_2.2.0                 future.apply_1.5.0           
## [139] misc3d_0.8-4                  data.table_1.12.8            
## [141] blob_1.2.1                    cummeRbund_2.28.0            
## [143] labeling_0.3                  splines_3.6.3                
## [145] Formula_1.2-3                 AnnotationHub_2.18.0         
## [147] ProtGenerics_1.18.0           RCurl_1.98-1.2               
## [149] hms_0.5.3                     colorspace_1.4-1             
## [151] base64enc_0.1-3               BiocManager_1.30.10          
## [153] nnet_7.3-14                   bookdown_0.19                
## [155] Rcpp_1.0.4.6                  RANN_2.6.1                   
## [157] MeSH.PCR.db_1.13.0            enrichplot_1.6.1             
## [159] R6_2.4.1                      grid_3.6.3                   
## [161] ggridges_0.5.2                lifecycle_0.2.0              
## [163] acepack_1.4.1                 curl_4.3                     
## [165] MeSH.Bsu.168.eg.db_1.13.0     gdata_2.18.0                 
## [167] leiden_0.3.3                  MeSH.AOR.db_1.13.0           
## [169] meshr_1.22.0                  DO.db_2.9                    
## [171] Matrix_1.2-18                 qvalue_2.18.0                
## [173] RcppAnnoy_0.0.16              RColorBrewer_1.1-2           
## [175] iterators_1.0.12              stringr_1.4.0                
## [177] htmlwidgets_1.5.1             polyclip_1.10-0              
## [179] triebeard_0.3.0               biomaRt_2.42.1               
## [181] purrr_0.3.4                   crosstalk_1.1.0.1            
## [183] gridGraphics_0.5-0            reactome.db_1.70.0           
## [185] globals_0.12.5                openssl_1.4.1                
## [187] htmlTable_1.13.3              patchwork_1.0.0.9000         
## [189] codetools_0.2-16              gtools_3.8.2                 
## [191] prettyunits_1.1.1             dbplyr_1.4.4                 
## [193] gtable_0.3.0                  tsne_0.1-3                   
## [195] DBI_1.1.0                     httr_1.4.1                   
## [197] KernSmooth_2.23-17            stringi_1.4.6                
## [199] progress_1.2.2                reshape2_1.4.4               
## [201] farver_2.0.3                  uuid_0.1-4                   
## [203] annotate_1.64.0               hexbin_1.28.1                
## [205] fdrtool_1.2.15                Rgraphviz_2.30.0             
## [207] xml2_1.3.2                    rvcheck_0.1.8                
## [209] IRkernel_1.1                  ggplotify_0.0.5              
## [211] Category_2.52.1               BiocVersion_3.10.1           
## [213] bit_1.1-15.2                  jpeg_0.1-8.1                 
## [215] ggraph_2.0.3                  pkgconfig_2.0.3              
## [217] knitr_1.28

9 License

Copyright (c) 2018 Koki Tsuyuzaki and Laboratory for Bioinformatics Research, RIKEN Center for Biosystems Dynamics Reseach Released under the Artistic License 2.0